<html>
<head><meta charset="utf-8"><title>cfgs as public API? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cfgs.20as.20public.20API.3F.html">cfgs as public API?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="152710785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cfgs%20as%20public%20API%3F/near/152710785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cfgs.20as.20public.20API.3F.html#152710785">(Dec 29 2018 at 17:18)</a>:</h4>
<p>I have a problem of needing to essentially provide a cfg-bool as a public API of a library. So far the only solution that comes to mind is to have a macro that spits out tokens provided certain cfgs were set, but that is very inconvenient to implement and not obvious to use.</p>



<a name="152710792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cfgs%20as%20public%20API%3F/near/152710792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cfgs.20as.20public.20API.3F.html#152710792">(Dec 29 2018 at 17:18)</a>:</h4>
<p>do we have any better solutions?</p>



<a name="157268802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cfgs%20as%20public%20API%3F/near/157268802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cfgs.20as.20public.20API.3F.html#157268802">(Jan 31 2019 at 12:42)</a>:</h4>
<p>I'm trying to understand what you mean by a "cfg-bool"? Is the intent to export a value that can somehow be used within attributes or other expansion-time constructs?</p>



<a name="157268824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cfgs%20as%20public%20API%3F/near/157268824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cfgs.20as.20public.20API.3F.html#157268824">(Jan 31 2019 at 12:43)</a>:</h4>
<p>Or is this just a single value that you want to be used <em>as</em> something that would act like <code>#[cfg(bool)]</code> depending on some internal function  of various cfg's it sees?</p>



<a name="157269967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cfgs%20as%20public%20API%3F/near/157269967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cfgs.20as.20public.20API.3F.html#157269967">(Jan 31 2019 at 13:04)</a>:</h4>
<p>Well, the problem I’m trying to solve is as follows: certain functions simply do not exist for targets A, B and C.</p>



<a name="157269976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cfgs%20as%20public%20API%3F/near/157269976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cfgs.20as.20public.20API.3F.html#157269976">(Jan 31 2019 at 13:04)</a>:</h4>
<p>internally within the library I have the <code>cfg</code>s that I work based on. Those are generated by the build script.</p>



<a name="157269984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cfgs%20as%20public%20API%3F/near/157269984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cfgs.20as.20public.20API.3F.html#157269984">(Jan 31 2019 at 13:05)</a>:</h4>
<p>Now how do I export that information to those targets so that they could decide whether to use the functions or implement some sort of a fallback.</p>



<a name="157270072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cfgs%20as%20public%20API%3F/near/157270072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cfgs.20as.20public.20API.3F.html#157270072">(Jan 31 2019 at 13:06)</a>:</h4>
<p>What I have so far is this (within my library)</p>
<div class="codehilite"><pre><span></span><span class="cp">#[cfg(not(function_a_exists))]</span><span class="w"></span>
<span class="n">macro_rules</span><span class="w"> </span><span class="n">with_function_a</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">((</span><span class="cp">$tree</span>: <span class="nc">tt</span><span class="p">)</span><span class="o">*</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="cp">#[cfg(function_a_exists)]</span><span class="w"></span>
<span class="n">macro_rules</span><span class="o">!</span><span class="w"> </span><span class="n">with_function_a</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">((</span><span class="cp">$tree</span>: <span class="nc">tt</span><span class="p">)</span><span class="o">*</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="cp">$($tree</span><span class="p">)</span><span class="o">*</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</pre></div>


<p>(and also similarly negative variant <code>with_not_function_a</code>) which is ugly and otherwise inconvenient.</p>



<a name="157270095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cfgs%20as%20public%20API%3F/near/157270095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cfgs.20as.20public.20API.3F.html#157270095">(Jan 31 2019 at 13:07)</a>:</h4>
<p>I would much rather just make the <code>function_a_exsists</code> cfg a part of my public API.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>